home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickTime / Programming Stuff / Documentation / develop articles / develop Issue 23 / Internet Config / IC 1.1 / ICAppSourceKit1.1 / Balloons.pl < prev    next >
Encoding:
Perl Script  |  1995-07-27  |  2.8 KB  |  133 lines  |  [TEXT/ttxt]

  1. #!perl
  2.  
  3. $balloons_strh_id = 26724;
  4.  
  5. # chdir "Rocky:Peter:Pascal:TCP Work:TCP Programs:Anarchie";
  6.  
  7. open(STDIN,"Balloons Data") || die "Failed to open input";
  8. open(STDOUT,">Balloons.r") || die "Failed to open output";
  9.  
  10. print <<INCLUDES;
  11. #include "Types.r"
  12. #include "BalloonTypes.r"
  13.  
  14. INCLUDES
  15.  
  16. @strings=();
  17.  
  18. while (<>) {
  19.   chop;
  20.   next if /^$/;
  21.   last if /^END$/;
  22.   die "Bad line '$_'" unless /(DIALOG|MENU)\s+(\d+)\s*(.*)/;
  23.   $dialog = $1 eq "DIALOG"; $id = $2; $name=$3;
  24.   @items=();
  25.     @menus=();
  26.     $menuitem=0;
  27.   while (<>) {
  28.     chop;
  29.     next if /^$/;
  30.     if ($dialog) {
  31.         last if /^END-DIALOG$/;
  32.         die "Bad dialog line '$_'" unless /^(\d+)\.(\d+)\s+(.*)/;
  33.         die "Quote in line" if /"/;
  34.         $base=($1-1)*4;
  35.         $item=$base+$2-1;
  36.         $index = &find_string($3);
  37.         $items[$item] = $index;
  38.         $items[$base+0] = 0 unless $items[$base+0];
  39.         $items[$base+1] = 0 unless $items[$base+1];
  40.         $items[$base+2] = 0 unless $items[$base+2];
  41.         $items[$base+3] = 0 unless $items[$base+3];
  42.     } else {
  43.         last if /^END-MENU$/;
  44.         die "Quote in line '$_'" if /"/;
  45.         die "Bad menu line '$_'" unless /^(\d) (.*)/ || /^(\d)$/;
  46.             if ($1 == 0) {
  47.               if ($1 eq $_) {
  48.                 $menus[$menuitem]='-';
  49.                 } else {
  50.                   $menus[$menuitem]= $2;
  51.                 }
  52.                 $menuitem++;
  53.             } else {
  54.                 $base=($menuitem-1)*4;
  55.                 $item=$base+$1-1;
  56.                 $index = &find_string($2);
  57.                 $items[$item] = $index;
  58.                 $items[$base+0] = 0 unless $items[$base+0];
  59.                 $items[$base+1] = 0 unless $items[$base+1];
  60.                 $items[$base+2] = 0 unless $items[$base+2];
  61.                 $items[$base+3] = 0 unless $items[$base+3];
  62.             }
  63.     }
  64.   }
  65.     if ($dialog) {
  66.       print <<"HEADER";
  67. resource 'hdlg' ($id,"$name") {
  68. \t2,0,0,0,0,
  69. \tHMSkipItem { },
  70. \t{
  71. HEADER
  72.     } else {
  73.         print <<"HEADER";
  74. resource 'hmnu' ($id,"$name") {
  75. \t2,0,0,0,
  76. \tHMSkipItem { },
  77. \t{
  78. HEADER
  79.     }
  80.   for $item (1..@items/4) {
  81.     $base = ($item-1)*4;
  82.     if ($items[$base+0] || $items[$base+1] ||
  83.         $items[$base+2] || $items[$base+3]) {
  84.             print "\t\tHMStringResItem { /* $item */\n";
  85.             if ($dialog) {
  86.           print <<"ITEM";
  87. \t\t\t{0,0},
  88. \t\t\t{0,0,0,0},
  89. ITEM
  90.             }
  91.       for $k (0..3) {
  92.         $index = $items[$base+$k];
  93.         if ($index) {
  94.           print "\t\t\t$balloons_strh_id,$index,\n";
  95.         } else {
  96.           print "\t\t\t0,0,\n";
  97.         }
  98.       }
  99.       print "\t\t},\n";
  100.     } else {
  101.          print "\t\tHMSkipItem { }, /* $item */\n";
  102.     }
  103.   }
  104.   print <<"TRAILER";
  105. \t}
  106. };
  107.  
  108. TRAILER
  109. }
  110.  
  111. print "resource 'STR#' ($balloons_strh_id,\"Balloon Help Strings\") {\n";
  112. print "\t{\n";
  113. for $index (1..@strings) {
  114.   print "\t\t/* $index */\n";
  115.   print "\t\t\"$strings[$index-1]\",\n";
  116. }
  117. print "\t}\n";
  118. print "};\n\n";
  119.  
  120. close(STDOUT);
  121. close(STDIN);
  122.  
  123. sub find_string {
  124.   local($s) = @_;
  125.   local($i);
  126.   for $i (1..@strings) {
  127.     return $i if $s eq $strings[$i-1];
  128.   }
  129.   $i = @strings;
  130.   $strings[$i] = $s;
  131.   return $i+1;
  132. }
  133.